package cn.tedu.utils;/**
 * @Author 金帮嘉诚 @Date 2021-07-15 星期四 19:00
 */
/*本类用于测试*/

import java.sql.*;

/**知识点*/
public class Jdbc {
    public static Connection getCon() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql:///cgb2105?characterEncoding=utf8";
        Connection connection = DriverManager.getConnection(url,"root","root");
        return connection;
    }

    public static void closeRPC(ResultSet resultSet, PreparedStatement preparedStatement,Connection connection){
        if (resultSet!=null){
            try {
                resultSet.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (preparedStatement!=null){
            try {
                preparedStatement.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (connection!=null){
            try {
                connection.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
    }
}
